-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes and improvements in SOLPSSimulation, SOLPSMesh and related functions #35
Fixes and improvements in SOLPSSimulation, SOLPSMesh and related functions #35
Conversation
… to SOLPSSimulation, other fixes.
Just updated the code by adding ion and neutral atom temperatures. The latter is not available in stand-alone B2.5 simulations. |
I renamed this PR because now it addresses not just #31 but in some degree #8 too. Replacing the algorithm for poloidal basis vectors calculation in |
Just noticed that conversion from poloidal to Cartesian coordinates in |
Sorry, I'm wrong here. It converts to Cartesian, so it's OK. |
…on on assignment to b_field and velocities in SOLPSSimulation.
Hey Vlad, I don't have any strong opinions on these improvements. I don't use this module as much at the moment, so I think opinions from the main users are more important. I'll let @jacklovell and @Mateasek give feedback on these changes. |
…_simulation_files. Removed radial_particle_flux and radial_area attributes from SOLPSSimulation.
…ort of B2.5 stand-alone simulations
Hi Matthew, thanks for reply. I need a couple more days to get this PR ready for review. |
In the first post, I summaraised the changes made in this PR and marked it ready for review. Hi @jacklovell and @Mateasek, I am awaiting your verdict). Hello @jrh-ccfe, could you please share any balance.nc file, so I could improve |
…*() methods, added setters instead.
…and *_f3d() interpolators.
…t.44. Made fort.44 version check strict again.
I updated balance.py and revert the change in the fort44 parser. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this Vlad: it's a huge amount of great work and a big improvement to the module overall. I've made some in-line comments on the code, but generally it is of a very good standard.
I've run the 3 demo scripts we currently have on a limited set of runs that I have access to and they seem to produce mostly the same results as before. I expect any small differences are a result of bug fixes. Have you done regression testing on any other SOLPS cases you have?
There's a few places in the code with large commented-out blocks: these can be removed if they won't be added back in later. I'm thinking in particular in solps_plasma.py, where there are several commented-out plotting methods which should live in demo scripts instead.
Also, considering the amount of change here it would be worth adding to the changelog while the changes are still fresh. I'll defer to @CnlPepper on whether this is a big enough change to warrant a 1.2 (or even a 2.0) release, or whether a 1.1.1 would be suitable.
cherab/solps/solps_plasma.py
Outdated
if self._total_rad is None: | ||
raise RuntimeError("Total radiation not available for this simulation") | ||
if self._total_radiation is None: | ||
raise RuntimeError("Total radiation not available for this simulation.") | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else
is not necessary after a raise
. This applies to all the total_radiation*
, b_field*
and eirene_simulation
properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code was before me, some properties threw errors when not initialized and some did not. I think, they should not throw errors. If a property is required for a function to work, that function must check if the value is set and throw a RuntimeError
if not. I've removed these raise
statements from properties and instead added them to functions that don't work without these properties.
cherab/solps/solps_plasma.py
Outdated
for k, sp in enumerate(self.species_list): | ||
if self.electron_velocities_cartesian is None: | ||
print('Warning! No electron velocity data available for this simulation.') | ||
electron_velocity = lambda x, y, z: Vector3D(0, 0, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a ConstantVector3D
object, not a lambda function.
cherab/solps/solps_plasma.py
Outdated
if isinstance(self.velocities_cartesian, np.ndarray): | ||
velocity = SOLPSVectorFunction3D(tri_index_lookup, tri_to_grid, self.velocities_cartesian[:, :, k, :]) | ||
if self.velocities_cartesian is not None: | ||
velocity = self.velocities_cartesian[k] | ||
else: | ||
velocity = lambda x, y, z: Vector3D(0, 0, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a ConstantVector3D
object, not a lambda function.
cherab/solps/solps_plasma.py
Outdated
else: | ||
electron_velocity = self.electron_velocities_cartesian | ||
plasma.electron_distribution = Maxwellian(self.electron_density_f3d, self.electron_temperature_f3d, electron_velocity, electron_mass) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace.
One other comment: if Axisymmetric wrappers of |
I agree, it would be best to remove redundant code. |
While there are large API changes to the SOLPSSimulation API, the core functionality for loading and generating Plasma objects The arguments for a major/minor version increment would be the degree of impact to the main usage of the package. This one lies on the border I suspect. As the active users of this package, you would be best placed to assess the impact on users and then decide if you want to go for v2.0.0 or v1.2.0. Please do add a changelog. I would recommend getting into the habit of checking if it needs updating with every pull request. |
cherab/solps/mesh_geometry.py
Outdated
must be 3 dimensional. Example shape is (4 x 32 x 98). | ||
In SOLPS notation: left/right - poloidal prev./next, bottom/top - radial prev./next. | ||
Cell indexing starts with 0 and -1 means no neighbour. | ||
:param ndarray neighbix: Array of radial indeces of neighbouring cells in order: left, bottom, right, top, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't it be neighbiy?
cherab/solps/solps_plasma.py
Outdated
|
||
self._eirene = value | ||
|
||
def b2_flux_to_velocity(self, poloidal_flux, radial_flux, parallel_velocity): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to make this method a standalone instead of class method, like it is in the case of EFITEquilibrium class? This class is becoming quite big, it would help decreasing it. Also the method itself could be useful/used for various purposes. The same could be done with eirene_flux_to_velocity
.
That is a large amount of work @vsnever, very nice. Thanks for all the work you put into it, especially when SOLPS is not the easiest code to understand and read! I would like to propose one more change, since this is quite major rewrite. I would suggest also removing the commented plotting methods from the SOLPSimulation class. I think the plots would be better done outside in a separate file, as it is with equilibrium plots in Cherab. I don't mean that you should be also adding it now. |
…inside/outside mesh in SOLPSTotalRadiatedPower.
@jacklovell, @Mateasek, @CnlPepper, thank you very much for the code review. I hope I addressed all the issues you raised. For three of them I left the comments (see above). If I did not leave a comment, it means that the issue is fixed exactly as you suggested.
When the data is read from the MDSPlus, the only difference should be in species velocities, because of the bug fix. When the data is read from the balance.nc file, then in addition to velocities, the density of impurity neutral atoms is different, because now it's obtained from the Eirene data. If the data is read from raw simulation files then the density of main plasma neutral atoms is also different because previously it was obtained from B2.
I updated the changelog suggesting a 1.2 version. In addition to the improvements you suggested, I removed redundant check for inside/outside mesh in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
@CnlPepper @Mateasek are you happy for these changes to be merged? |
Yes, sorry I am new to this, forgot to click on approve. Very nice piece of work! |
Happy here, nice work! |
@jacklovell, @Mateasek, @CnlPepper, thanks a lot! @jacklovell, please do not close #34 when this is merged. There is still plenty of work to do. |
This PR addresses the issues #8, #20, #31, #33, #34, #36 and #37.
Issue #8 is addressed in the following way:
Safe to use
SOLPSFunction2D
andSOLPSVectorFunction2D
classes are implemented. They replaceSOLPSFunction3D
andSOLPSVectorFunction3D
. For 3D, useAxisymmetricMapper(SOLPSFunction2D)
andVectorAxisymmetricMapper(SOLPSVectorFunction2D)
.SOLPSMesh
andSOLPSSimulation
can now be initialised without modification of hidden attributes;SOLPSMesh
has new attributes for basis vectors, cell connection areas, indices of neighbouring cells and new functionsto_poloidal()
andto_cartesian()
for converting vectors defined on a grid from/to (poloidal, radial)/(R, Z);species_list
inSOLPSSimulation
is a list of (name, charge) pairs now instead of a list of strings;Setting
b_field
andvelocities
vectors in curvilinear poloidal coordinates (epol, erad, etor) automaticaly setsb_field_cylindrical
andvelocities_cylindrical
(eR, eφ, eZ) and vice versa (note: etor = -eφ);Incorrect calculation of basis vectors using cell centres is fixed (basis vectors are defined by left and bottom faces of the cell);
The code for
mesh.triangles
andmesh.triangle_to_grid_map
creation is vectorised (as all other code wherever possible);SOLPSSimulation
now has setters for its properties;load_solps_from_mdsplus()
,load_solps_from_raw_output()
andload_solps_from_balance()
do not brakeSOLPSSimulation
interface anymore;load_solps_from_mdsplus()
andload_solps_from_raw_output()
are made more robust. Now both support B2 standalone runs. Error handling is added toload_solps_from_mdsplus()
for some optional attributes that may not be present on the server;Other small improvements.
Issue #20 is fixed.
*_f2d()
and*_f3d()
interpolators are added for plasma parameters. For vectors_carteisan
suffix is used instead of_f3d
.Issue #31 is fixed. Now if the neutral densities from Eirene are available, they replace the neutral densities from B2.
Issue #33 is fixed using
lookup_isotope()
andlookup_element()
methods. The plasma composition is defined from nuclear charge, atomic mass number and electrical charge. This is more robust than parsing a string with species names.Issue #34 is addressed by parsing the following additional quantities in
load_solps_from_mdsplus()
andload_solps_from_raw_output()
:The fluxes are not stored in
SOLPSSimulation
, but used to calculate velocities.Issue #36 is fixed. The parallel velocity and the B2 fluxes (in s-1) defined on cell faces are used in
b2_flux_to_velocity()
to calculate velocities at cell centres. If neutral atom fluxes from Eirene (in m-2 s-1) defined at cell centres are available, they are used ineirene_flux_to_velocity()
replacing the B2 ones.Issue #37 is fixed. Now all arrays are row-major. However, the indexing is inverted. The correct index order now is: (radial, poloidal) or (species, radial, poloidal) for scalars and (vector component, radial, poloidal) or (species, vector component, radial, poloidal) for vectors. This should improve the performance in typical workflows.
Remaining issues:
Electron velocities are still not read from SOLPS data.
Molecular and total H-alpha emission are still not read from SOLPS data.